package com.icexxx.icemock.mock;

import java.util.ArrayList;
import java.util.List;

import cn.hutool.core.util.RandomUtil;

public class EmailMock implements IceMock {

	@Override
	public String mock(Integer minVal, Integer maxVal, Integer minWidth, Integer maxWidth, String enums, String key) {
		List<String> suffixList = createSuffix();
		StringBuilder sb = new StringBuilder();
		if(minWidth == null) {
			minWidth = 3;
		}
		if(maxWidth == null) {
			maxWidth = 3;
		}
		int width = RandomUtil.randomInt(minWidth, maxWidth + 1);
		for (int i = 0; i < width; i++) {
			int randomInt = RandomUtil.randomInt(100);
			if (randomInt > 5) {
				char randomChar = RandomUtil.randomChar();
				sb.append(randomChar);
			} else {
				sb.append("_");
			}
		}
		int randomInt = RandomUtil.randomInt(100);
		if(randomInt < 80) {
			String string = sb.toString();
			sb = new StringBuilder(string.toLowerCase());
		}
		String randomSuffix = RandomUtil.randomEle(suffixList);
		sb.append("@");
		sb.append(randomSuffix);
		return sb.toString();
	}

	private List<String> createSuffix() {
		List<String> suffixList = new ArrayList<>();
		suffixList.add("qq.com");
		suffixList.add("sina.com");
		suffixList.add("sogou.com");
		suffixList.add("126.com");
		suffixList.add("163.com");
		suffixList.add("tom.com");
		return suffixList;
	}

}
